{{template "base" .}}

{{define "content"}}
<div class="search-container">
    <div class="search-header">
        <h1>搜索结果</h1>
        <p>关键词: "{{.keyword}}" - 找到 {{.postList.DataNum}} 篇文章</p>
    </div>

    <div class="search-results">
        {{if gt .postList.DataNum 0}}
            {{range $id, $post := .postList.Lists}}
            <article class="search-item">
                <h2 class="post-title">
                    <a href="/read/{{$post.ID}}">{{$post.Title}}</a>
                </h2>
                <div class="post-meta">
                    <span class="post-date">{{$post.CreateTime.Format "2006-01-02"}}</span>
                    <span class="post-category">{{$post.TypeName}}</span>
                    <span class="post-views">{{$post.ReadCount}} 阅读</span>
                </div>
                <div class="post-excerpt">
                    {{$post.Content}}
                </div>
                <div class="post-tags">
                    {{range $post.Tags}}
                    <span class="tag">{{.}}</span>
                    {{end}}
                </div>
            </article>
            {{end}}

            <!-- 分页 -->
            {{if gt .postList.PageNum 1}}
            <div class="pagination">
                {{if gt .currentPage 1}}
                <a href="/search?keyword={{.keyword}}&page={{subtract .currentPage 1}}" class="prev">上一页</a>
                {{end}}
                
                {{range $i := sequence .postList.PageNum}}
                <a href="/search?keyword={{$.keyword}}&page={{$i}}" class="{{if eq $i $.currentPage}}current{{end}}">{{$i}}</a>
                {{end}}
                
                {{if lt .currentPage .postList.PageNum}}
                <a href="/search?keyword={{.keyword}}&page={{add .currentPage 1}}" class="next">下一页</a>
                {{end}}
            </div>
            {{end}}
        {{else}}
            <div class="no-results">
                <p>没有找到包含 "{{.keyword}}" 的文章</p>
                <a href="/" class="back-home">返回首页</a>
            </div>
        {{end}}
    </div>
</div>
{{end}}